package com.mzw.huaxiarealestatebackend.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzw.huaxiarealestatebackend.dao.StaffKpiRecordDao;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.StaffKpiRecord;
import com.mzw.huaxiarealestatebackend.service.StaffKpiRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (StaffKpiRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-12-11 16:21:56
 */
@Service("staffKpiRecordService")
public class StaffKpiRecordServiceImpl implements StaffKpiRecordService {
    @Resource
    private StaffKpiRecordDao staffKpiRecordDao;

    @Override
    public List<StaffKpiRecord> queryAll() {
        List<StaffKpiRecord> staffKpiRecords = staffKpiRecordDao.selectList(null);
        return staffKpiRecords;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param krcdNo 主键
     * @return 实例对象
     */
    @Override
    public StaffKpiRecord queryById(String krcdNo) {
        QueryWrapper<StaffKpiRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("krcd_no", krcdNo);
        StaffKpiRecord staffKpiRecord = staffKpiRecordDao.selectOne(queryWrapper);
        return staffKpiRecord;
    }

    /**
     * 分页查询
     * @param current    当前页码
     * @param size      分页大小
     * @return
     */
    @Override
    public BackPage<StaffKpiRecord> queryByPage(int current, int size) {
        BackPage<StaffKpiRecord> backPage= new BackPage<>();
        //创建Page对象，传递两个参数：当前页    每页显示记录数
        Page<StaffKpiRecord> page = new Page<>(current,size);
        //调用mp方法实现分页
        staffKpiRecordDao.selectPage(page,null);
        //IPage<User> pageModel = userMapper.selectPage(page,null);
        backPage.setContentList(page.getRecords());
        backPage.setCurrentPage(page.getCurrent());
        backPage.setTotalPage(page.getPages());
        backPage.setTotalNum(page.getTotal());
        return backPage;
    }

    /**
     * 新增数据
     *
     * @param staffKpiRecord 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(StaffKpiRecord staffKpiRecord) {
        int insert = staffKpiRecordDao.insert(staffKpiRecord);
        return insert > 0;
    }

    /**
     * 修改数据
     *
     * @param staffKpiRecord 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(StaffKpiRecord staffKpiRecord) {
        int update = staffKpiRecordDao.update(staffKpiRecord);
        return update > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param krcdNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String krcdNo) {
        int i = staffKpiRecordDao.deleteById(krcdNo);
        return i > 0;
    }
}
